package com.example;

import android.app.Activity;
import android.os.*;

public class Handler_Test extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("Thread-name:" + Thread.currentThread().getId());

        setContentView(R.layout.main);

        HandlerThread  handlerThread = new HandlerThread("Handler_Test_Thread") ;
        handlerThread.start();
        MyHandler handler = new MyHandler(handlerThread.getLooper());
        Message msg =  handler.obtainMessage();
        msg.sendToTarget();

        Bundle bundle = new Bundle();
        bundle.putString("age","age:20");
        msg.setData(bundle);
    }

    class MyHandler extends Handler{

        public MyHandler(){}

        public MyHandler(Looper looper){
            super(looper);
        }

        @Override
        public void handleMessage(Message msg) {

            System.out.println("Bundle content:"+msg.getData().getString("age"));
            System.out.println("Handled massage--->:Thread-name:" + Thread.currentThread().getId());
        }
    }

}
